import type { PageParams } from "@/types/common"
import type { Role, RoleAddParams, RoleData, RoleUserData } from "@/types/system"
import { request } from "@/utils/reuqest"

/**
 * 获取角色列表
 * @returns
 */
export const getRoleListAPI = () => {
    return request<Role[]>('/park/sys/role')
  }

  /**
 * 获取tree权限列表
 * @returns
 */
export const getTreeListAPI = ()=>{
    return request<RoleData[]>('/park/sys/permision/all/tree');
  }

/**
 * 查询当前角色详情-权限和分配人数
 * @returns
 */
export const getRoleDetailAPI = (roleId: number) =>{
  return request<RoleUserData>(`/park/sys/role/${roleId}`)
}



/**
 * 获取角色成员列表
 * @param roleId 角色id
 * @param params 分页参数
 * @returns 
 */
export const getRoleUserAPI = (roleId: number, params?: PageParams) => {
  return request<RoleUserData>(`/park/sys/roleUser/${roleId}`, 'GET', params)
}

// 添加角色
export const addRoleAPI = (data: RoleAddParams) => {
  return request<Role>('/park/sys/role', 'POST', data)
}

// 删除角色
export const deleteRoleAPI = (id: number) => {
  return request<Role>(`/park/sys/role/${id}`, 'DELETE')
}

// 编辑回显
export const getRoleEditAPI = (roleId: number) => {
  return request<RoleUserData>(`/park/sys/role/${roleId}`)
}

/**
 * 
 * 角色管理-修改角色
 * @param data 
 * @returns
 */
export const updateRoleUserAPI = (data: RoleAddParams) => {
  return request('/park/sys/role', 'PUT', data)
}